package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.security.SecureRandom;
import java.util.List;

/**
 * @author with葡萄成熟时
 * @version 1.0
 */

@RestController("adminSetmealController")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    SetmealService setmealService;


    /**
     * @description: 新增套餐
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 上午12:37 2024/11/8
     */
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")//缓存
    @PostMapping("/admin/setmeal")
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {

        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * @description: 分页查询
     * @param: [setmealPageQueryDTO]
     * @return: com.sky.result.Result<com.sky.result.PageResult>
     * @author Wait葡萄成熟时
     * @date: 下午12:31 2024/11/8
     */
    @GetMapping("/admin/setmeal/page")
    @ApiOperation("分页查询")

    public Result<PageResult> selectSetmealPage(SetmealPageQueryDTO setmealPageQueryDTO) {

        PageResult pageResult = setmealService.selectSetmealPage(setmealPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * @description: 根据id查询套餐
     * @param: [id]
     * @return: com.sky.result.Result<com.sky.vo.SetmealVO>
     * @author Wait葡萄成熟时
     * @date: 下午12:50 2024/11/8
     */
    @GetMapping("/admin/setmeal/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> selectSetmealById(@PathVariable Long id) {

        SetmealVO setmealVO = setmealService.selectSetmealById(id);
        return Result.success(setmealVO);
    }

    /**
     * @description: 批量删除套餐
     * @param: [ids]
     * @return: com.sky.result.Result
     * @author Wait葡萄成熟时
     * @date: 下午1:15 2024/11/8
     */
    @DeleteMapping("/admin/setmeal")
    @ApiOperation("批量删除套餐")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)//清理所有缓存
    public Result deleteSetmeal(@RequestParam List<Long> ids) {

        setmealService.deleteSetmeal(ids);

        return Result.success();
    }

    /**
     * @description: 修改套餐
     * @param: [setmealDTO]
     * @return: com.sky.result.Result
     * @author Wait葡萄成熟时
     * @date: 下午1:35 2024/11/8
     */
    @PutMapping("/admin/setmeal")
    @ApiOperation("修改套餐")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)//清理所有缓存
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){

        setmealService.updateSetmeal(setmealDTO);

        return Result.success();
    }

    /**
     * @description: 套餐起售、停售
     * @param: [status, id]
     * @return: com.sky.result.Result
     * @author Wait葡萄成熟时
     * @date: 下午1:49 2024/11/8
     */
    @PostMapping("/admin/setmeal/status/{status}")
    @ApiOperation("套餐起售、停售")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)//清理所有缓存
    public Result startOrNot(@PathVariable Integer status,@RequestParam Long id){

        setmealService.startOrNot(status,id);
        return Result.success();
    }
}
